package com.baseweb.webadmin.core.model.dao.impl;

import com.baseweb.webadmin.core.model.dao.ByMoneyLogDao;
import com.baseweb.webadmin.core.model.mapper.ByMoneyLogMapper;
import com.baseweb.webadmin.core.model.pojo.ByMoneyLog;
import com.baseweb.webadmin.core.model.pojo.ByMoneyLogExample;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class ByMoneyLogDaoImpl extends SqlSessionDaoSupport implements ByMoneyLogDao {

    @Autowired
    ByMoneyLogMapper byMoneyLogMapper;

    @Override
    public List<ByMoneyLog> selectListByPage(Integer userId, Integer start, Integer offset) {
        ByMoneyLogExample example = new ByMoneyLogExample();
        ByMoneyLogExample.Criteria criteria = example.createCriteria();
        if(userId != null){
            criteria.andUserIdEqualTo(userId);
        }
        example.setOrderByClause(String.format("id desc limit %s,%s", start, offset));
        return byMoneyLogMapper.selectByExample(example);
    }

    @Override
    public Integer selectListCount(Integer userId) {
        ByMoneyLogExample example = new ByMoneyLogExample();
        ByMoneyLogExample.Criteria criteria = example.createCriteria();
        if(userId != null){
            criteria.andUserIdEqualTo(userId);
        }
        return byMoneyLogMapper.countByExample(example);
    }

}
